//
//  Today_VC.m
//  Run
//
//  Created by BetaTheta on 16/3/31.
//  Copyright © 2016年 BetaTheta. All rights reserved.
//

#import "Today_VC.h"

#import "DYDate_CollectionViewCell.h"

@interface Today_VC ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UICollectionView *dataCollectionView;
@property (nonatomic, strong) CAShapeLayer *trackShapeLayer;
@property (nonatomic, strong) CAShapeLayer *progressShapeLayer;
@property (nonatomic, strong) UIView *circleView;
@property (nonatomic, strong) UILabel *dateLabel;

@end

@implementation Today_VC
@synthesize progressView;


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"今天";
    [self createDateCollectionView];
    [self createProgressView];
    
}
#pragma mark - 日历
- (void)createDateCollectionView{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    self.dataCollectionView = [[UICollectionView alloc] initWithFrame: CGRectMake(0, 0, WIDTH, (WIDTH - 60) / 7 ) collectionViewLayout:layout];
    // 边缘弹动
    _dataCollectionView.bounces = NO;
    _dataCollectionView.scrollEnabled = YES;
    // 布局设置
    // 滚动方向
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    // cell大小
    layout.itemSize = CGSizeMake((WIDTH - 6 * 20 - 20) / 7 , (WIDTH - 6 * 20 - 20) / 7);

    // 行列间距
    layout.minimumInteritemSpacing = 20;
//    layout.minimumLineSpacing = 0;
   // 边界 上左下右
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    //CollectionView上的背景颜色
    self.dataCollectionView.backgroundColor = [UIColor whiteColor];;
    
    _dataCollectionView.delegate = self;
    _dataCollectionView.dataSource = self;
    
    [_dataCollectionView registerClass:[DYDate_CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    [self.view addSubview:_dataCollectionView];
//    self.navigationItem.titleView = _dataCollectionView;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 7;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DYDate_CollectionViewCell *dateCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    dateCell.dateLabel.text = @"7";
    return dateCell;
    
}
#pragma mark - 环形渐变色
- (void)createProgressView{
#pragma mark -
    self.trackShapeLayer = [CAShapeLayer layer];
    self.trackShapeLayer.frame = CGRectMake(WIDTH / 2 -  WIDTH * 0.3, WIDTH / 4, WIDTH *0.6 , WIDTH * 0.6 );//设置shapeLayer的尺寸和位置
    //    self.bgShapeLayer.position = self.view.center;
    self.trackShapeLayer.fillColor = [UIColor clearColor].CGColor;//填充颜色为ClearColor
    
    //设置线条的宽度和颜色
    self.trackShapeLayer.lineWidth = 13.0f;
    self.trackShapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
    
    // 指定线的边缘是圆的
    self.trackShapeLayer.lineCap = kCALineCapRound;
    //创建出圆形贝塞尔曲线
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, WIDTH *0.6 , WIDTH * 0.6 )];
    //让贝塞尔曲线与CAShapeLayer产生联系
    self.trackShapeLayer.path = circlePath.CGPath;
    
    //添加并显示
    [self.view.layer addSublayer:self.trackShapeLayer];
    
    
#pragma mark -
    //创建出CAShapeLayer
    self.progressShapeLayer = [CAShapeLayer layer];
    self.progressShapeLayer.frame = CGRectMake(0, 0, WIDTH *0.6 , WIDTH * 0.6 );
    
    self.progressShapeLayer.fillColor = [UIColor clearColor].CGColor;//填充颜色为ClearColor
    
    //设置线条的宽度和颜色
    self.progressShapeLayer.lineWidth = 10.0f;
    self.progressShapeLayer.strokeColor = [UIColor orangeColor].CGColor;
    
    // 指定线的边缘是圆的
    self.progressShapeLayer.lineCap = kCALineCapRound;
    
    
    //让贝塞尔曲线与CAShapeLayer产生联系
    self.progressShapeLayer.path = circlePath.CGPath;
    
    //添加并显示
    [self.trackShapeLayer addSublayer:self.progressShapeLayer];
    
    //    现在我们要用到CAShapeLayer的两个参数，strokeEnd和strokeStart
    //Stroke:用笔画的意思
    //    在这里就是起始笔和结束笔的位置
    //    Stroke为1的话就是一整圈，0.5就是半圈，0.25就是1/4圈。以此类推
    //
    //    如果我们把起点设为0，终点设为0.75
    
    //设置stroke起始点
    self.progressShapeLayer.strokeStart = 0;
    self.progressShapeLayer.strokeEnd = 0.75;
#pragma mark -
    self.circleView = [[UIView alloc] initWithFrame:CGRectMake(WIDTH * 0.1, WIDTH * 0.1, WIDTH *0.4 , WIDTH * 0.4)];
    _circleView.layer.cornerRadius = _circleView.bounds.size.width / 2;
    _circleView.backgroundColor = [UIColor orangeColor];
    [_progressShapeLayer addSublayer:_circleView.layer];
    
//    self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CWIDTH - 15, CWIDTH - 15)];
//    _dateLabel.text = @"7";
//    _dateLabel.textColor = [UIColor whiteColor];
//    
//    _dateLabel.textAlignment = NSTextAlignmentCenter;
//    [_circleView addSubview:_dateLabel];
    
}
- (void)progressChange
{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
